<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../css/api.css" />
		<link rel="stylesheet" type="text/css" href="../../css/style.css" />
		<style type="text/css">
			html,body{ background:#F7F8FA; }
			.balance_history{ background-color: #fff; padding: 0;}
			.balance_history li{ padding: 10px 16px; position: relative;}
			.balance_history li:active{ background-color: #f8f8f8;}
			.balance_history li::after{ display:block; position: absolute; content: ""; left: 0; right: 0; bottom: 0; height: 1px; background-color: #dedede; overflow: hidden; transform: scaleY(0.5);}
			.balance_history h4{ display:block; font-size: 15px; font-weight: 400; color: #666; line-height: 32px;}
			.balance_history p{ font-size: 12px; color: #999; line-height: 23px;}
			.balance_history b{ display:block; font-size: 16px; font-weight: 400; color: #121212; line-height: 23px; text-align: right;}
			.balance_history span{ display: block; font-size: 12px; line-height: 32px; text-align: right;}
			.status0 { background-color: #edf5fc !important; padding: 2.5px 7.5px; color: #0e7ae2;}
			.status1 { background-color: #eef9f6; padding: 2.5px 7.5px; color: #31c268;}
			.status2 { background-color: #fbf3f4; padding: 2.5px 7.5px; color: #e75959;}
			
			.color1{ color: #F6AA42 !important;}
			.color2{ color: #333 !important;}
			.sk-three-bounce {
			  margin: 0 auto;
			  width: 80px;
			  text-align: center; }
			  .sk-three-bounce .sk-child {
				width: 13.5px;
				height: 13.5px;
				background-color: #3262F1;
				border-radius: 100%;
				display: inline-block;
				-webkit-animation: sk-three-bounce 1.4s ease-in-out 0s infinite both;
						animation: sk-three-bounce 1.4s ease-in-out 0s infinite both; }
			  .sk-three-bounce .sk-bounce1 {
				-webkit-animation-delay: -0.32s;
						animation-delay: -0.32s; }
			  .sk-three-bounce .sk-bounce2 {
				-webkit-animation-delay: -0.16s;
						animation-delay: -0.16s; }

			@-webkit-keyframes sk-three-bounce {
			  0%, 80%, 100% {
				-webkit-transform: scale(0);
						transform: scale(0); }
			  40% {
				-webkit-transform: scale(1);
						transform: scale(1); } }

			@keyframes sk-three-bounce {
			  0%, 80%, 100% {
				-webkit-transform: scale(0);
						transform: scale(0); }
			  40% {
				-webkit-transform: scale(1);
						transform: scale(1); }
			}
			.more{ padding: 1.20rem 0; text-align: center; font-size: 0.26rem; color: #999; line-height: 0.60rem;}
			.display-none{ display:none; }
			.text-center { text-align: center !important; }
		</style>
	</head>
	<body>
		
		<!--余额记录start-->
		<div class="balance_history">
			<ul id="creditlist">
			</ul>
			<script id="creditlist_template" type="text/template">
				{{ for (var i = 0, len = it.length; i < len; i++) { }}
				<li tapmode onclick="opDetail({{=it[i].id}},{{=it[i].paytype}});">
				<div class="m_cell_hd m_cell_primary">
						<h4>{{=it[i].memo}}</h4>
						<p>{{=it[i].createtime}}</p>
					</div>
					<div class="m_cell_ft">
						{{? it[i].txid > 0 }}<span><i class="status{{=it[i].txstatus}}">{{=it[i].txstatusstr}}</i></span>{{?}}
						<b {{? it[i].credit > 0 }}class="color1"{{??}}class="color2"{{?}}>{{ if (it[i].credit > 0) { }}+{{ } }}{{=it[i].credit}}</b>
					</div>
				</li>
				{{ } }}
			</script>
			
		</div>
		<div class="text-center display-none" style="padding: 110px 0 !important;" id="divnodata">
			<div class="text-center"><img src="../../image/nodata.png" style="margin:0 auto;width:41px;height:auto;"></div>
			<p class="text-center" style="font-size:12px;color:#9f9f9f;margin-top:15px;">暂无记录</p>
		</div>
		<div class="more display-none">
			<p>没有更多了</p>
		</div>
		<!--余额记录end-->
	</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/app.js"></script>
	<script type="text/javascript" src="../../script/doT.js"></script>
	<script type="text/javascript">
		var page = 1;
		var UILoading;
		apiready = function() {
			api.parseTapmode();
			UILoading = api.require('UILoading');
			$api.css($api.dom('.balance_history'), 'display: none');
			showloading();
			getJsonFromAPI();
			
			api.addEventListener({
					name:"scrolltobottom"
			},function(ret,err){
				getJsonFromAPI();
			});
			api.addEventListener({
                name: 'navitembtn'
            }, function(ret, err) {
                if (ret.type == 'left') {
					api.closeWin({
					});
                }
            });
		}
		function opDetail(logid,paytype) {
			if(paytype == 4)
			{
				//4提现
				openNavWin('#ddd','creditdetail_win','creditdetail_frm.html','提现详情',false,false,true,[],{logid:logid,paytype:paytype});
			}
		}
		function getJsonFromAPI(newsid) {
			//从接口获取查询数据
			api.getPrefs({
				key: 'user_info'
			}, function(ret, err) {
				if (ret.value) {
					var userinfo = JSON.parse(ret.value);
					api.ajax({
						url: ApiUrl + '/v1/credit/'+page,
						method: 'get',
						cache: false,
						timeout: 10,
						headers: {
							authorization: kAppKey+';'+userinfo.access_token+';'+userinfo.uid
						}
					}, function(ret, err) {
						hideloading();
						$api.css($api.dom('.balance_history'), 'display: block');
						if (ret) {
							
							if(ret.list.length > 0)
							{
								$api.addCls($api.byId('divnodata'),'display-none');
								var isAppend = true;
								if(page==1)
								{
									isAppend = false;
								}
								page++;
								var creditlist = ret.list;
								UpdateList('creditlist','creditlist_template',creditlist,isAppend);
							}
							else
							{
								if(page==1)
								{
									UpdateList('creditlist','creditlist_template',ret.list,false);
									$api.removeCls($api.byId('divnodata'),'display-none');
								}
							}
							
						} else {
							if(err.statusCode==402)
							{
								Relogin();
							}
							else
							{
								console.log(JSON.stringify(err));
								toast('网络异常');
							}
						}
					});
				}
			});
		}
		//渲染数据
		function UpdateList(domId,templateId,jsondata,isAppend) {
			//console.log(JSON.stringify(jsondata));
			var act_content = $api.byId(domId);
			var tempFn = doT.template($api.byId(templateId).innerHTML);
			var resultText = tempFn(jsondata);
			//alert(isAppend);
			console.log(resultText);
			if(isAppend)
			{
				$api.append(act_content, resultText);
			}
			else
			{
				$api.html(act_content, resultText);
			}
			api.parseTapmode();
		}
	</script>
</html>